package com.ordering.service.order.impl;

import com.ordering.constant.ResultResponse;
import com.ordering.dao.order.OrderDao;
import com.ordering.dao.order.impl.OrderDaoImpl;
import com.ordering.entity.Order;
import com.ordering.entity.Page;
import com.ordering.service.order.OrderService;

public class OrderServiceImpl implements OrderService{
	
	OrderDao orderDao = new OrderDaoImpl();
	
	@Override
	public ResultResponse add(Order order, String itemIds) {
		ResultResponse response = new ResultResponse();
		try {
			
			
			
			response.setResult(orderDao.add(order,itemIds));
		} catch (Exception e) {
			response.setCode(ResultResponse.CODE_Fail);
			response.setMessage(e.getMessage());
			e.printStackTrace();
		}
		return response;
	}

	@Override
	public ResultResponse delect(Order order) {
		ResultResponse response = new ResultResponse();
		try {
			response.setResult(orderDao.delect(order));
		} catch (Exception e) {
			response.setCode(ResultResponse.CODE_Fail);
			response.setMessage(e.getMessage());
			e.printStackTrace();
		}
		return response;
	}

	@Override
	public ResultResponse get4page(Order order, Page page) {
		ResultResponse response = new ResultResponse();
		try {
			response.setResult(orderDao.get4page(order,page));
		} catch (Exception e) {
			response.setCode(ResultResponse.CODE_Fail);
			response.setMessage(e.getMessage());
			e.printStackTrace();
		}
		return response;
	}

	@Override
	public ResultResponse updateStatus(Order order) {
		ResultResponse response = new ResultResponse();
		try {
			response.setResult(orderDao.updateStatus(order));
		} catch (Exception e) {
			response.setCode(ResultResponse.CODE_Fail);
			response.setMessage(e.getMessage());
			e.printStackTrace();
		}
		return response;
	}

	@Override
	public ResultResponse count(Order order) {
		ResultResponse response = new ResultResponse();
		try {
			response.setResult(orderDao.count(order));
		} catch (Exception e) {
			response.setCode(ResultResponse.CODE_Fail);
			response.setMessage(e.getMessage());
			e.printStackTrace();
		}
		return response;
	}

    @Override
    public ResultResponse getById(int id)
    {
        ResultResponse response = new ResultResponse();
        try {
            response.setResult(orderDao.getById(id));
        } catch (Exception e) {
            response.setCode(ResultResponse.CODE_Fail);
            response.setMessage(e.getMessage());
            e.printStackTrace();
        }
        return response;
    }

}
